#include "AttribBaseForm.h"
#include <QLineEdit>
#include <QComboBox>
#include <QCheckBox>
AttribBaseForm::AttribBaseForm(QWidget *parent) : QWidget(parent)
{

}

void AttribBaseForm::SetChannelID(int channelID)
{
    m_channelID = channelID;
}

void AttribBaseForm::SetDeviceID(int deviceID)
{
    m_deviceID = deviceID;
}

void AttribBaseForm::SetProtoName(QString protoName)
{
    m_protoName = protoName;
}

void AttribBaseForm::SetCurrentTreeItem(QTreeWidgetItem *currentItem)
{
    m_currentTreeItem = currentItem;
}

void AttribBaseForm::ShowWindow()
{
    m_initAfter = false;
    InitUIData();
    m_initAfter = true;
}


void AttribBaseForm::InitUIData()
{

}

void AttribBaseForm::saveModel()
{

}

void AttribBaseForm::connectAllEdit()
{
    // 遍历所有的子控件
    foreach (QWidget* widget, this->findChildren<QWidget*>())
    {
        QLineEdit * lineEdit = qobject_cast<QLineEdit *>(widget);
        if(lineEdit)
            connect(lineEdit,&QLineEdit::textChanged,this,&AttribBaseForm::on_textChanged);
        else
        {
            QComboBox * combox = qobject_cast<QComboBox *>(widget);
            if(combox)
                connect(combox,&QComboBox::currentTextChanged,this,&AttribBaseForm::on_textChanged);
            else
            {
                QCheckBox * checkbox = qobject_cast<QCheckBox *>(widget);
                if(checkbox)
                    connect(checkbox,&QCheckBox::stateChanged,this,&AttribBaseForm::on_status_chanaged);
                else
                {
                    QTableWidget * tableWidget = qobject_cast<QTableWidget *>(widget);
                    if(tableWidget)
                        connect(tableWidget,&QTableWidget::itemChanged,this,&AttribBaseForm::itemChanged);
                }
            }
        }
    }
}

void AttribBaseForm::on_textChanged(const QString &)
{
    if(m_initAfter)
        saveModel();
}

void AttribBaseForm::on_status_chanaged(int value)
{
    if(m_initAfter)
        saveModel();
}

void AttribBaseForm::itemChanged(QTableWidgetItem *item)
{
    if(m_initAfter)
        saveModel();
}
